/**
 * 
 */
package com.wskj.library.advice.controller;

import java.util.List;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;

import com.wskj.library.pojo.Advice;
import com.wskj.library.service.AdviceService;
import com.wskj.library.service.impl.AdviceServiceImpl;
import com.wskj.util.Page;
import com.wskj.util.StringUtil;

/**
 * @author 胡洋
 * @describe 公告列表页面 
 * @Date 2018年3月26日上午11:05:59
 * @version 1.0
 */
@WebServlet(urlPatterns = "/advice/list.do")
public class AdviceListServlet extends HttpServlet {
	AdviceService service=new AdviceServiceImpl(); 
	protected void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
			throws javax.servlet.ServletException, java.io.IOException {
	  
		doPost(req,resp);
	};

	
	protected void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
			throws javax.servlet.ServletException, java.io.IOException {
	    int index=StringUtil.nullToInt(req.getParameter("index"));
		Page<Advice> page=new Page<>(index, 10);
		
		List<Advice> advices=service.queryAdvices(index, page.getPageSize());
		
		long counts=service.getAdvicesCounts();
		page.setCounts(counts);
		page.setData(advices);
		
		req.setAttribute("page", page);
		req.getRequestDispatcher("/WEB-INF/page/advice/list.jsp").forward(req, resp);	
	};
	
	
}
